package com.example.kafka.config;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.kafka.dto.UserDto;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
public class KafkaConsumer {
    @KafkaListener(topics = {"statistic_topic"})
    public void listen(ConsumerRecord<String, Object> record) {
        Object value = record.value();
        UserDto dto = JSON.parseObject(value.toString(), UserDto.class);
        if (dto.getAge() == 20) {
            throw new RuntimeException("lalala");
        }
        System.out.println();
    }
}
